<?php  if ( ! defined('IN_DiliCMS')) exit('No direct script access allowed');
	class Car_cate_m extends CI_Model{
		function __construct()
		{
			parent::__construct();
		}
			
		function get_slider_cars($cateid=0)	//获取幻灯片线路,及图片
		{
			$datawhere=" and model=5";
			if($cateid){
				$datawhere.=" and (INSTR(car_class,'-$cateid,') or INSTR(car_class,',$cateid-'))";
			}
			$sql="select  content,name,folder,type  from dili_u_m_car_rent as l inner join dili_attachments as a on a.content=l.id where slider=1 $datawhere  group by content limit 5";
			//	print_r($sql);
			$slider_lines=$this->db->query($sql)->result();
			return $slider_lines;
		}
		
		function get_commend_cars($cateid=0)	//获取汽车推荐线路列表
		{
			$datawhere=" and model=5";
			if($cateid){
				$datawhere.=" and INSTR(car_class,',$cateid-')";
			}
			$sql="select  id,car_title,per_price,car_info,name,folder,type  from dili_u_m_car_rent as l inner join dili_attachments as a on a.content=l.id where tuijian=1 $datawhere  group by content limit 5";
			//	print_r($sql);
			$commend_cars=$this->db->query($sql)->result();
			return $commend_cars;
		}		
		function get_category_list($cateid=0,$carclass_p)	//获取一级类下汽车子类及其内容列表
		{
			if((int)$cateid && $carclass_p){
				foreach($carclass_p as $key=>$value){
					$sql="select id,car_title,per_price,car_info,tuijian,car_model,seating_num from  dili_u_m_car_rent where  INSTR(car_class,'-$key') limit 10";
					$category_list[$key]=$this->db->query($sql)->result();
		
				}
				//		print_r($category_list);
				return $category_list;
					
			}
			return false;
			//	echo $sql;
				
		}		
		function get_art_num($cateid=0)	//获取某类下的记录数
		{
			if ((int)$cateid){
				$sql="select count(id) as icount from  dili_u_m_car_rent  where  INSTR(car_class,',$cateid-') or  INSTR(car_class,'-$cateid,')";
				$art_num=$this->db->query($sql)->row_array();
				//		print_r($art_num);
				return $art_num["icount"];
			}else{
				return 0;
			}
		}
		function get_subclass_list($cateid=0,$begin_record=0,$per_page=10)	//获取子类旅游线路列表
		{
			if((int)$cateid){
				if(!$begin_record){
					$begin_record=0;
				}
				$sql="select id,car_title,per_price,car_info,tuijian,car_model,seating_num,car_conditions from  dili_u_m_car_rent  where  INSTR(car_class,'-$cateid,') or INSTR(car_class,',$cateid-') group by id limit $begin_record,$per_page";
				$subclass_list['list']=$this->db->query($sql)->result();

				$sql_annex="select id,model,name,folder,type from  dili_u_m_car_rent as l inner join dili_attachments as a on l.id=a.content where  (INSTR(car_class,'-$cateid,') or INSTR(car_class,',$cateid-') ) and model=5 group by id limit $begin_record,$per_page";
				$annex=$this->db->query($sql_annex)->result();
				foreach($annex as $item){
					$subclass_list['annex'][$item->id]=$item;
				}
		//			print_r($sql_annex);
				return $subclass_list;
			}
			return false;		
		}
		function get_carInfo($carId=0)	//获取文章内容
		{
			if ($carId){
				$sql="select id,car_class,car_title,per_price,car_info,tuijian,car_model,seating_num,car_conditions from  dili_u_m_car_rent  where id=".$carId."   limit 1 ";
				//	exit($sql);
				$carInfo['list']=$this->db->query($sql)->result();
				$sql_annex="select name,folder,realname,type,image from   dili_attachments  where content=".$carId." and model=5 order by image desc limit 5 ";
				//	exit($sql);
				$carInfo['annex'][$carId]=$this->db->query($sql_annex)->result();
									
				return $carInfo;
			}else{
				return false;
			}
		}						
	}